<template>
  <div class="icons">
  <swiper :options="swiperOption">
    <swiper-slide v-for= "(page,index) of pages" :key= "index">
      <div class="icon" v-for="item of page" :key="item.id">
        <img :src="item.imgUrl" class="icon-img">
        <p class="icon-desc">{{item.desc}}</p>
      </div>
    </swiper-slide>
  </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        loop: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="scss" scoped>
  @import '~styles/variables';
  @import '~styles/mixins';
  .icons >>> .swiper-container{
    height: 0;
    padding-bottom: 50%;
  }
  .icons{
    .icon{
      width: 25%;
      text-align: center;
      float: left;
      padding-top: 0.1rem;
      .icon-img{
        width: 1.1rem;
        height: 1.1rem;
        margin-bottom: 0.1rem;
      }
      .icon-desc{
        color: $iconColor;
        font-size: 0.28rem;
        @include ellipsis();
      }
    }
  }
</style>
